package com.wwtech.epp.ui.activity.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwtech.epp.R;
import com.wwtech.epp.application.AppConfig;
import com.wwtech.epp.entity.WorkCategory;
import com.wwtech.epp.ui.activity.base.MyBaseFragment;
import com.wwtech.epp.ui.activity.main.component.DaggerWorkComponent;
import com.wwtech.epp.ui.activity.main.contract.WorkContract;
import com.wwtech.epp.ui.activity.main.module.WorkModule;
import com.wwtech.epp.ui.activity.main.presenter.WorkPresenter;
import com.wwtech.epp.ui.adapter.main.WorkCategoryAdapter;
import com.wwtech.epp.utils.UIUtils;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author hzp
 * @Package com.wwtech.epp.ui.activity.main
 * @Description: $description
 * @date 2017/08/21 11:14:20
 */

public class WorkFragment extends MyBaseFragment implements WorkContract.View {

    @Inject
    WorkPresenter mPresenter;
    @Inject
    WorkCategoryAdapter workCategoryAdapter;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.seal_more)
    ImageView sealMore;
    @BindView(R.id.title)
    RelativeLayout title;
    @BindView(R.id.layout_top)
    LinearLayout layoutTop;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_work, null);
        ButterKnife.bind(this, view);
        Bundle mBundle = getArguments();
        layoutTop.setPadding(0, (int) (UIUtils.getStatusBarHeight(getActivity()) * 0.8), 0, 0);
        tvTitle.setText("工作");
        initData();
        return view;
    }

    private void initData() {
        recyclerview.setAdapter(workCategoryAdapter);
        mPresenter.getWorkCategory();
    }


    @Override
    protected void setupFragmentComponent() {
        DaggerWorkComponent
                .builder()
                .appComponent(((AppConfig) getActivity().getApplication()).getApplicationComponent())
                .workModule(new WorkModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void setPresenter(WorkContract.WorkContractPresenter presenter) {
        mPresenter = (WorkPresenter) presenter;
    }

    @Override
    protected void initDataFromLocal() {

    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    public void setWorkCategory(WorkCategory workCategory) {
        workCategoryAdapter.setNewData(workCategory.getData());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void fetchData() {

    }
}